# SceneManager.gd
class_name SceneManager
extends Node

# 场景路径常量
const MAIN_MENU = "res://scenes/UI/title_screen.tscn"
const GAME = "res://scenes/game.tscn"
const END_SCREEN = "res://scenes/UI/game_end_screen.tscn"

# 当前场景
var current_scene: Node = null
#全局死亡计数
var global_death_count: int = 0

func _ready():
	# 初始加载主界面
	load_scene(MAIN_MENU)

# 加载场景
func load_scene(path: String):
	# 如果有当前场景，移除它
	if current_scene:
		current_scene.queue_free()
		print("已删除场景：", current_scene)
	
	# 加载新场景
	var new_scene = load(path).instantiate()
	get_tree().root.add_child.call_deferred(new_scene)
	current_scene = new_scene
	
	print("已加载场景: ", path)

# 转到游戏场景
func go_to_game():
	global_death_count = 0  # 重置死亡计数
	load_scene(GAME)

# 返回主菜单
func go_to_main_menu():
	load_scene(MAIN_MENU)

func go_to_end_screen():
	load_scene(END_SCREEN)

# 设置全局死亡次数
func set_global_death_count(count: int):
	global_death_count = count

# 获取全局死亡次数
func get_global_death_count() -> int:
	return global_death_count
